package com.hwd.gmall.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hwd.gmall.model.product.SkuSaleAttrValue;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * sku销售属性表的 mapper 映射
 *
 * @author 黄伟东/Victor
 * @date 2022/4/20 20:10
 */
@Mapper
public interface SkuSaleAttrValueMapper extends BaseMapper<SkuSaleAttrValue> {

    /**
     * 查询指定spu的所有销售属性值与sku对应关系
     *
     * @param spuId spuId
     * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     */
    @Select("SELECT sku_id," +
            " GROUP_CONCAT( DISTINCT sale_attr_value_id ORDER BY sale_attr_value_id SEPARATOR '|' ) values_id \n" +
            "FROM sku_sale_attr_value \n" +
            "WHERE spu_id = #{spuId} GROUP BY sku_id;")
    List<Map<Object, Object>> getSkuSaleAttrValueInfo(@Param("spuId") Long spuId);
}
